package com.grass.p019lv.fragment.search;

import android.os.Bundle;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.AttentionContentBean;
import com.androidx.p013lv.base.bean.InventionThreeBean;
import com.androidx.p013lv.base.bean.StarBean;
import com.androidx.p013lv.base.bean.event.AttentionEvent;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.invention.HttpAttention;
import com.androidx.p013lv.invention.adapter.AdapterStar;
import com.grass.p019lv.databinding.FragmentPeopleBinding;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/* renamed from: com.grass.lv.fragment.search.SearchPeopleFragment */
public class SearchPeopleFragment extends LazyFragment<FragmentPeopleBinding> implements OnRefreshListener, OnLoadMoreListener, ItemClickListener {
    String HTTP_CANCEL_TAG = "cancelAttention";
    String HTTP_SAVE_TAG = "saveAttention";
    String HTTP_TAG = "queryContentList";
    AdapterStar adapter;
    InventionThreeBean bean;
    HttpCallback<BaseRes<AttentionContentBean>> cancelHttp;
    int index;
    int page = 1;
    HttpCallback<BaseRes<AttentionContentBean>> saveHttp;
    String searchTxt;

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return R.layout.fragment_people;
    }

    public static SearchPeopleFragment newInstance(String str) {
        Bundle bundle = new Bundle();
        bundle.putString(Key.TXT, str);
        SearchPeopleFragment searchPeopleFragment = new SearchPeopleFragment();
        searchPeopleFragment.setArguments(bundle);
        return searchPeopleFragment;
    }

    @Override // androidx.fragment.app.Fragment
    public void setArguments(Bundle bundle) {
        super.setArguments(bundle);
        this.searchTxt = bundle.getString(Key.TXT);
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        EventBus.getDefault().register(this);
        ((FragmentPeopleBinding) this.binding).refresh.setOnRefreshListener(this);
        ((FragmentPeopleBinding) this.binding).refresh.setOnLoadMoreListener(this);
        ((FragmentPeopleBinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        this.adapter = new AdapterStar();
        ((FragmentPeopleBinding) this.binding).recycler.setAdapter(this.adapter);
        this.adapter.setItemListener(this);
        ((FragmentPeopleBinding) this.binding).statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.grass.p019lv.fragment.search.SearchPeopleFragment.View$OnClickListenerC30081 */

            public void onClick(View view) {
                SearchPeopleFragment.this.page = 1;
                SearchPeopleFragment.this.getInfo();
            }
        });
        getInfo();
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        if (this.page == 1) {
            AdapterStar adapterStar = this.adapter;
            if (!(adapterStar == null || adapterStar.getData() == null || this.adapter.getData().size() <= 0)) {
                this.adapter.clear();
            }
            if (!NetUtil.isNetworkAvailable()) {
                ((FragmentPeopleBinding) this.binding).statusLayout.showNoNet();
                return;
            }
            ((FragmentPeopleBinding) this.binding).statusLayout.showLoading();
        }
        HttpUtils.getInsatance().get(UrlManager.getInsatance().queryContentList(this.page, this.searchTxt), new HttpCallback<BaseRes<StarBean>>(this.HTTP_TAG) {
            /* class com.grass.p019lv.fragment.search.SearchPeopleFragment.C30092 */

            public void onLvSuccess(BaseRes<StarBean> baseRes) {
                if (SearchPeopleFragment.this.binding != null) {
                    ((FragmentPeopleBinding) SearchPeopleFragment.this.binding).refresh.finishRefresh();
                    ((FragmentPeopleBinding) SearchPeopleFragment.this.binding).refresh.finishLoadMore();
                    if (baseRes.getCode() == 200) {
                        if (baseRes.getData() != null && baseRes.getData().getList() != null && baseRes.getData().getList().size() > 0) {
                            SearchPeopleFragment.this.adapter.setDomain(baseRes.getData().getDomain());
                            if (SearchPeopleFragment.this.page == 1) {
                                SearchPeopleFragment.this.adapter.setData(baseRes.getData().getList());
                                ((FragmentPeopleBinding) SearchPeopleFragment.this.binding).refresh.resetNoMoreData();
                            } else {
                                SearchPeopleFragment.this.adapter.setDatasInEnd(baseRes.getData().getList());
                            }
                            SearchPeopleFragment.this.page++;
                        } else if (SearchPeopleFragment.this.page == 1) {
                            ((FragmentPeopleBinding) SearchPeopleFragment.this.binding).statusLayout.showEmpty();
                        } else {
                            ((FragmentPeopleBinding) SearchPeopleFragment.this.binding).refresh.finishLoadMoreWithNoMoreData();
                        }
                    } else if (SearchPeopleFragment.this.page == 1) {
                        ((FragmentPeopleBinding) SearchPeopleFragment.this.binding).statusLayout.showError();
                    } else {
                        ToastUtils.getInstance().showWeak(baseRes.getMsg());
                    }
                }
            }
        });
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        getInfo();
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnRefreshListener
    public void onRefresh(RefreshLayout refreshLayout) {
        this.page = 1;
        getInfo();
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onDestroy() {
        super.onDestroy();
        HttpUtils.getInsatance().cancelTag(this.HTTP_TAG);
        HttpUtils.getInsatance().cancelTag(this.HTTP_SAVE_TAG);
        HttpUtils.getInsatance().cancelTag(this.HTTP_CANCEL_TAG);
        EventBus.getDefault().unregister(this);
    }

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
        if (!isOnClick()) {
            if (view.getId() == R.id.iv_cover || view.getId() == R.id.btn_sum) {
                ARouter.getInstance().build(Constance.STAR_INFO_ACTIVITY).withInt("type", ((InventionThreeBean) this.adapter.getDataInPosition(i)).getContentId()).withString(Key.TXT, "搜索").navigation();
            } else if (view.getId() == R.id.iv_attention) {
                InventionThreeBean inventionThreeBean = (InventionThreeBean) this.adapter.getDataInPosition(i);
                this.bean = inventionThreeBean;
                this.index = i;
                if (inventionThreeBean.isAttention()) {
                    HttpAttention.getInstance().cancelAttention(this.bean.getContentId(), cancelHttp());
                } else {
                    HttpAttention.getInstance().saveAttention(this.bean.getContentId(), saveHttp());
                }
            }
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onGetMessage(AttentionEvent attentionEvent) {
        AdapterStar adapterStar = this.adapter;
        if (!(adapterStar == null || adapterStar.getData() == null || this.adapter.getData().size() == 0)) {
            for (int i = 0; i < this.adapter.getItemCount(); i++) {
                InventionThreeBean inventionThreeBean = (InventionThreeBean) this.adapter.getDataInPosition(i);
                if (attentionEvent.getContentId() == inventionThreeBean.getContentId()) {
                    inventionThreeBean.setAttention(attentionEvent.isAttention());
                    this.adapter.notifyItemChanged(i);
                    return;
                }
            }
        }
    }

    public HttpCallback<BaseRes<AttentionContentBean>> cancelHttp() {
        if (this.cancelHttp == null) {
            this.cancelHttp = new HttpCallback<BaseRes<AttentionContentBean>>(this.HTTP_CANCEL_TAG, getActivity()) {
                /* class com.grass.p019lv.fragment.search.SearchPeopleFragment.C30103 */

                public void onLvSuccess(BaseRes<AttentionContentBean> baseRes) {
                    if (baseRes.getCode() == 200) {
                        SearchPeopleFragment.this.bean.setAttention(false);
                        SearchPeopleFragment.this.adapter.notifyItemChanged(SearchPeopleFragment.this.index);
                        return;
                    }
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            };
        }
        return this.cancelHttp;
    }

    public HttpCallback<BaseRes<AttentionContentBean>> saveHttp() {
        if (this.saveHttp == null) {
            this.saveHttp = new HttpCallback<BaseRes<AttentionContentBean>>(this.HTTP_SAVE_TAG, getActivity()) {
                /* class com.grass.p019lv.fragment.search.SearchPeopleFragment.C30114 */

                public void onLvSuccess(BaseRes<AttentionContentBean> baseRes) {
                    if (baseRes.getCode() != 200) {
                        return;
                    }
                    if (baseRes.getCode() == 200) {
                        SearchPeopleFragment.this.bean.setAttention(true);
                        SearchPeopleFragment.this.adapter.notifyItemChanged(SearchPeopleFragment.this.index);
                        return;
                    }
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            };
        }
        return this.saveHttp;
    }
}
